package com.lazy.lib.util;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

/**
 * @author kome.Jiangmy
 * @version 1.0
 * @created 2012-9-28 下午2:04:35
 */
public class ConfigUtil {
	
	/**
	 * 读取配置
	 * 
	 * @param filePath
	 * @return
	 */
	public static Properties loadProperties(String filePath) {
		Properties properties = new Properties();
		InputStream inputStream = null;
		try {
			URL resource = ConfigUtil.class.getClassLoader().getResource(filePath);
			if (resource == null) {
				System.err.println("Failed load properties, file[" + filePath + "] not exists, please check it !!!!!!!!!\n");
				return properties;
			}
			inputStream = ConfigUtil.class.getClassLoader().getResourceAsStream(filePath);
			properties.load(inputStream);
		} catch (IOException e) {
			System.err.println("Failed load properties file[" + filePath + "], please check it !!!!!!!!!\n");
		} finally {
			try {
				if (inputStream != null) {
					inputStream.close();
				}
			} catch (Exception e2) {
			}
		}
		System.out.println("--------------------- load properties from " + filePath + " ---------------------");
		for (Object key : properties.keySet()) {
			System.out.println(key + "=" + properties.get(key));
		}
		System.out.println("--------------- finish load properties " + filePath + " sucess !!!! -------------");
		return properties;
	}
	
	private ConfigUtil() {
	}
	
	public static void main(String[] args) {
		loadProperties("conf.properties");
		loadProperties("log4j.properties");
		// loadProperties("*.properties");
	}
}
